<h2 class="mat-display-1">Fitness trend configuration</h2>

<mat-dialog-content class="mat-body-1">

  <mat-accordion *ngIf="initialized">

    <mat-expansion-panel>
      <mat-expansion-panel-header>
        <mat-panel-title>
          Estimated stress scores
        </mat-panel-title>
        <mat-panel-description>
          Case where you don't own (or forgot) Heart Rate Monitor or Cycling Power Meter
        </mat-panel-description>
      </mat-expansion-panel-header>

      <div fxLayout="column" fxLayoutAlign="start start">
        <div fxFlex>
          <mat-slide-toggle
            [(ngModel)]="fitnessTrendConfigDialogData.fitnessTrendConfigModel.allowEstimatedPowerStressScore"
            [disabled]="!isEstimatedPowerStressScoreToggleEnabled">
            Enable Cycling Estimated PSS (Power Stress Scores) when estimated power data is available
          </mat-slide-toggle>

          <div *ngIf="!isEstimatedPowerStressScoreToggleEnabled" class="hint">

            <mat-icon [style.vertical-align]="'bottom'" color="warn" fontSet="material-icons-outlined">
              warning
            </mat-icon>
            PSS Estimation is currently disabled. To enable it, make sure that:
            <ul>
              <li>You set one or several <strong>Cycling Functional Threshold Power</strong> in <a
                (click)="dialogRef.close()" [routerLink]="'/athleteSettings'">dated
                athlete settings</a>. A wrong ftp can cause too big/low PSS scores on activities.
              </li>
              <li>You switch <strong>ON</strong> the power meter data toggle identified by the icon
                <mat-icon [style.vertical-align]="'bottom'" fontSet="material-icons-outlined">flash_on
                </mat-icon>
                (on screen behind).
              </li>
              <li>You set the "Heart Rate Stress Score" calculation mode to <strong>HRSS</strong> (below
                option).
              </li>
              <li>
                You set your weight in your <a href="https://www.strava.com/settings/profile"
                                               target="_blank">strava.com
                profile</a> to allow strava to estimate power data on your next cycling activities
                (required to compute <i>PSS</i>).
              </li>
              <li>
                Your cycling activities must have correct elevation data. Read Strava elevation <a
                href="https://support.strava.com/hc/en-us/articles/115001294564-Elevation-on-Strava-FAQs"
                target="_blank">FAQ</a> and <a
                href="https://support.strava.com/hc/en-us/articles/216919447-Elevation-for-Your-Activity"
                target="_blank">Notes</a> to fix your activities if needed. A "Clear and re-sync
                activities" can be required after any fix.
              </li>
            </ul>
          </div>
        </div>
        <div fxFlex="10px"></div>
        <div fxFlex>
          <mat-slide-toggle
            [(ngModel)]="fitnessTrendConfigDialogData.fitnessTrendConfigModel.allowEstimatedRunningStressScore"
            [disabled]="!isEstimatedRunningStressScoreToggleEnabled">
            Enable Running Estimated RSS (Running Stress Score)
          </mat-slide-toggle>

          <div *ngIf="!isEstimatedRunningStressScoreToggleEnabled" class="hint">
            <mat-icon [style.vertical-align]="'bottom'" color="warn" fontSet="material-icons-outlined">
              warning
            </mat-icon>
            RSS Estimation is currently disabled. To enable it, make sure that:
            <ul>
              <li>You set your one or several <strong>Running Functional Threshold Pace</strong> in <a
                (click)="dialogRef.close()" [routerLink]="'/athleteSettings'">dated
                athlete settings</a>.
              </li>
              <li>You set the "Heart Rate Stress Score" calculation mode to <strong>HRSS</strong></li>
            </ul>
          </div>
        </div>
      </div>
    </mat-expansion-panel>

    <mat-expansion-panel>
      <mat-expansion-panel-header>
        <mat-panel-title>Exclude activities from fitness trend</mat-panel-title>
        <mat-panel-description>Case where you want to ignore activities by their name</mat-panel-description>
      </mat-expansion-panel-header>

      <div class="hint">
        Unwanted activities can be excluded from the fitness trend based on their names and patterns.<br/><br/>

        A use case could be "Mountain Bike Downhill" activities without a heart rate monitor or power meter.
        Athlete took the ski lift many times. If athlete enables the "Cycling Power Stress Score
        (PSS) Estimation", stress scores are gonna to be huge and not relevant of athlete efforts due to the
        important total ascent coming from ski lifts. And so the fitness trend could be impacted by these
        unwanted
        stress scores. Assuming athlete had put the tag <strong>"#MTBDH"</strong> on all his mountain bike
        downhill activities,
        appending a line with <strong>"#MTBDH"</strong> in the below input will exclude mountain bike downhill
        activities from fitness trend.<br/><br/>

        Note: You may need to change some activities name directly in strava and launch a <strong>"Sync all
        activities"</strong> to view changes.
      </div>

      <textarea (change)="onIgnoreActivityNamePatternsChange()"
                [(ngModel)]="ignoreActivityNamePatterns"
                matInput
                placeholder="Enter activity name patterns exclusion (1 per line, case sensitive)"
                rows="5"></textarea>

    </mat-expansion-panel>

    <mat-expansion-panel>
      <mat-expansion-panel-header>
        <mat-panel-title>
          Exclude activities until a date
        </mat-panel-title>
        <mat-panel-description>
          Can be useful to ignore previous seasons for example
        </mat-panel-description>
      </mat-expansion-panel-header>

      <div class="hint">
        You can exclude activities from fitness trend before a specific date.<br/><br/>
        Leaving an empty field means no exclusion.<br/><br/>
        Note: The starting date will be set on the first activity available after that date.
      </div>

      <mat-form-field>
        <input (dateChange)="onIgnoreBeforeDateChange()"
               [(ngModel)]="ignoreBeforeDate"
               [matDatepicker]="datePickerTo"
               [max]="ignoreBeforeMaxDate"
               matInput
               placeholder="Ignore activities before">
        <mat-datepicker-toggle [for]="datePickerTo" matSuffix></mat-datepicker-toggle>
        <mat-datepicker #datePickerTo></mat-datepicker>
      </mat-form-field>

    </mat-expansion-panel>

    <mat-expansion-panel>
      <mat-expansion-panel-header>
        <mat-panel-title>
          Start with existing fitness and fatigue values
        </mat-panel-title>
        <mat-panel-description>
          Fitness trend will start with these values.
        </mat-panel-description>
      </mat-expansion-panel-header>

      <div class="hint">
        Fitness trend will start with the below values.<br/><br/>
        Leaving an empty field equals to set a value of <strong>0</strong>
      </div>

      <div fxLayout="column" fxLayoutAlign="start start">
        <mat-form-field fxFlex>
          <input
            (change)="onInitialFitnessChange()"
            [(ngModel)]="fitnessTrendConfigDialogData.fitnessTrendConfigModel.initializedFitnessTrendModel.ctl"
            matInput
            min="1"
            type="number"/>
          <mat-placeholder>
            Fitness starting value
          </mat-placeholder>
        </mat-form-field>
        <span fxFlex="1"></span>
        <mat-form-field fxFlex>
          <input
            (change)="onInitialFatigueChange()"
            [(ngModel)]="fitnessTrendConfigDialogData.fitnessTrendConfigModel.initializedFitnessTrendModel.atl"
            matInput
            min="1"
            type="number"/>
          <mat-placeholder>
            Fatigue starting value
          </mat-placeholder>
        </mat-form-field>
      </div>

    </mat-expansion-panel>

    <mat-expansion-panel>
      <mat-expansion-panel-header>
        <mat-panel-title>
          Heart rate stress score calculation mode
        </mat-panel-title>
        <mat-panel-description>
          Choose how stress scores is being computed from heart rate data
        </mat-panel-description>
      </mat-expansion-panel-header>

      <mat-radio-group (change)="onModeChange()"
                       [(ngModel)]="fitnessTrendConfigDialogData.fitnessTrendConfigModel.heartRateImpulseMode">
        <mat-radio-button [value]="HeartRateImpulseMode.HRSS">HRSS: Heart Rate Stress Score (recommend)
        </mat-radio-button>
        <mat-radio-button [value]="HeartRateImpulseMode.TRIMP">TRIMP: Training Impulse (not recommend)
        </mat-radio-button>
      </mat-radio-group>

      <div
        *ngIf="(fitnessTrendConfigDialogData.fitnessTrendConfigModel.heartRateImpulseMode === HeartRateImpulseMode.TRIMP)">
				<span>
					<mat-icon [style.vertical-align]="'bottom'" color="warn"
                    fontSet="material-icons-outlined">warning</mat-icon>
					When heart rate stress score calculation method is set to TRIMP (Training Impulse):
					<ul>
						<li>
							Training Zones will be disabled because TRIMP has a scale missmatch with Training Zones.
						</li>
						<li>
							Cycling Power Stress Scores (PSS) will not be taken into account because TRIMP scores are not scaled with PSS stress scores.
						</li>
						<li>
							Running Stress Scores (RSS) will not be taken into account because TRIMP scores are not scaled with RSS stress scores.
						</li>
						<li>
							Swimming Stress Scores (SSS) will not be taken into account because TRIMP scores are not scaled with SSS stress scores.
						</li>
					</ul>
				</span>
      </div>

    </mat-expansion-panel>

  </mat-accordion>

  <div class="note">
    Note: the configuration of fitness trend is stored locally only. It is not synced across browsers where plugin
    is installed.
  </div>

</mat-dialog-content>

<mat-dialog-actions>
  <button (click)="onSave()" color="primary" mat-dialog-close mat-stroked-button>Save</button>
  <span fxFlex="1"></span>
  <button (click)="onCancel()" color="primary" mat-dialog-close mat-stroked-button>Cancel</button>
</mat-dialog-actions>
